package offerv1;

public class Offer18 {
    public ListNode deleteNode(ListNode head, int val) {
        ListNode virtualNode = new ListNode(-1), index = head, pre = virtualNode;
        virtualNode.next = head;
        while (index != null) {
            if (index.val == val) {
                pre.next = pre.next.next;
                break;
            }
            pre = index;
            index = index.next;
        }
        return virtualNode.next;
    }
}
